package com.lagou.service.impl;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class HelloServiceImpl implements HelloService {

    @Override
    public String sayHello(String name, int timeToWait) {
        return "hello:"+name;
    }
    private static AtomicInteger count = new AtomicInteger(0);
    @Override
    public String methodA(String name) {
        long i = (long) (Math.random()*100);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行a,"+count.addAndGet(1));
        return "methodA";
    }

    @Override
    public String methodB(String name) {
        long i = (long) (Math.random()*100);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行b,"+count.addAndGet(1));
        return "methodB";
    }

    @Override
    public String methodC(String name) {
        long i = (long) (Math.random()*100);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行c,"+count.addAndGet(1));

        return "methodC";
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++) {
            long r = (long) (Math.random()*100);
            System.out.println(r);
        }
    }
}
